<template>
  <div id="ticket-orders">
    <nav aria-label="breadcrumb" role="navigation" class="bg-white">
      <ol class="breadcrumb">
        <li class="breadcrumb-item">
          <router-link to="/attractions/ticket/orders"
            >景点门票订单</router-link
          >
        </li>
        <li class="breadcrumb-item active" aria-current="page">列表</li>

        <li class="breadcrumb-item ms-auto">
          <router-link to="/attractions">景点</router-link>
        </li>
      </ol>
    </nav>

    <div class="card">
      <div class="card-body py-1">
        <form>
          <div class="row">
            <div class="col-1">
              <my-date-picker
                id="beginDate"
                v-model="beginDate"
                name="sc.beginDate"
                placeholder="开始日期"
              ></my-date-picker>
            </div>
            <div class="col-1">
              <my-date-picker
                id="endDate"
                v-model="endDate"
                name="sc.endDate"
                placeholder="截止日期"
              ></my-date-picker>
            </div>
            <div class="col-1">
              <input
                type="textfield"
                class="form-control"
                size="6"
                placeholder="订单号"
                v-model.trim="orderNo"
              />
            </div>
            <div class="col-1">
              <select
                class="form-select"
                v-model.number="status"
                name="sc.status"
              >
                <option value="-1">订单状态</option>
                <option value="0">待处理</option>
                <option value="1">处理中</option>
                <option value="2">已完成</option>
                <option value="4">已取消</option>
              </select>
            </div>
            <div class="col-1">
              <select class="form-select" v-model.number="sc.pageSize">
                <option value="5">5</option>
                <option value="25">25</option>
                <option value="50">50</option>
                <option value="100">100</option>
                <option value="500">500</option>
              </select>
            </div>

            <div class="col">
              <button
                type="button"
                class="btn btn-primary"
                @click.stop="search()"
              >
                查找
              </button>
              <button
                type="button"
                class="btn btn-secondary ms-2"
                @click.stop="reset()"
              >
                重置
              </button>
            </div>
          </div>
        </form>
      </div>
      <table class="table table-striped table-sm small">
        <thead>
          <tr>
            <th>订单号</th>
            <th>客户</th>
            <th>景点名称</th>
            <th>门票日期</th>
            <th>价格</th>
            <th>张数</th>
            <th>预订人</th>
            <th>总金额</th>
            <th>生成时间</th>
            <th>状态</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <template v-for="info in dataList">
            <tr>
              <td>
                {{ info.orderNo }}
              </td>
              <td>{{ info.customerName }}</td>
              <td>
                {{ info.attractionName }}
              </td>
              <td>{{ info.travelDate }}</td>
              <td>{{ info.price }}</td>
              <td>{{ info.count }}</td>
              <td>{{ info.operator }}</td>
              <td>{{ info.total }}</td>
              <td>{{ info.createTime }}</td>
              <td>{{ getStatusDesc(info.status) }}</td>
              <td class="">
                <router-link :to="`/attractions/ticket/order/` + info.id"
                  >详情</router-link
                >
              </td>
            </tr>
            <tr
              v-if="info.remark"
            >
              <td colspan="15" class="text-end">{{ info.remark }}</td>
              <td colspan="2"></td>
            </tr>
          </template>
          <tr v-if="dataList.length === 0">
            <td colspan="18" class="text-center">未找到符合的数据</td>
          </tr>
        </tbody>
      </table>
    </div>

    <nav id="pagination-box" class="float-end">
      <my-pagination
        name="pagination"
        :row-count="sc.rowCount"
        :page-total="sc.pageTotal"
        :page-no="sc.pageNo"
        @next-page="nextPage"
        @prev-page="prevPage"
        @direct-page="directPage"
      ></my-pagination>
    </nav>
  </div>
</template>

<script>
import {
  searchTicketOrders,
  showTicketOrderStatus,
  uploadTicketOrder,
} from "@/api/attraction.js";
import MyDatePicker from "@/components/my-datepicker.vue";
import MyPagination from "@/components/my-pagination.vue";

export default {
  components: {
    MyDatePicker,
    MyPagination,
  },
  data() {
    return {
      dataList: [],
      customers: [],
      sc: {
        rowCount: 0,
        pageNo: 1,
        pageSize: 25,
        pageTotal: 0,
      },
      beginDate: "",
      endDate: "",
      orderNo: "",
      customerId: -1,
      name: "",
      hotelName: "",
      status: -1,
    };
  },
  mounted: function () {
    this.search();
  },
  activated: function () {
    this.search();
  },
  methods: {
    back: function () {
      this.$router.go(-1);
    },
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    showLoading: function (loadingText) {
      this.$store.commit("showLoading", {
        loading: true,
        loadingText: loadingText,
      });
    },
    hideLoading: function () {
      this.$store.commit("showLoading", { loading: false });
    },
    search: function () {
      this.showLoading();
      const params = {
        "sc.pageNo": this.sc.pageNo,
        "sc.pageSize": this.sc.pageSize,
        "sc.beginDate": this.beginDate,
        "sc.orderNo": this.orderNo,
        "sc.endDate": this.endDate,
        "sc.name": this.name,
        "sc.status": this.status,
      };
      searchTicketOrders(
        params,
        (v) => {
          this.dataList = v.dataList;
          this.sc = v.page;

          // if (v.dataList.length === 0) {
          //   this.showErrMsg('没找到任何东西')
          // }
        },
        () => {
          this.hideLoading();
        }
      );
    },
    reset: function () {
      this.beginDate = "";
      this.endDate = "";
      this.orderNo = "";
      this.customerId = -1;
      this.name = "";
      this.hotelName = "";
      this.status = -1;
    },
    getStatusDesc: function (status) {
      return showTicketOrderStatus(status);
    },
    prevPage: function () {
      this.sc.pageNo = this.sc.pageNo - 1;
      if (this.sc.pageNo < 1) this.sc.pageNo = 1;
      this.search();
    },
    nextPage: function () {
      this.sc.pageNo = this.sc.pageNo + 1;
      this.search();
    },
    directPage: function (pageNo) {
      this.sc.pageNo = pageNo;
      this.search();
    },
  },
};
</script>
